//
//  MailboxBindingSecondVC.m
//  MRBang
//
//  Created by 铅笔 on 16/5/13.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "MailboxBindingSecondVC.h"
#import "MoreMessageVC.h"

@interface MailboxBindingSecondVC ()
@property (nonatomic,strong) UITextField *textField_email;

@property (nonatomic,strong) UIButton *button_getCheckCode;

@end

@implementation MailboxBindingSecondVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"绑定邮箱";
    
    [self initWithAllSubviews];
}

#pragma mark ---- 创建子视图
- (void) initWithAllSubviews
{
    //label 提示字样
    UILabel *label_text = [[UILabel alloc] initWithFrame:CGRectMake(46*PROPORTION_WIDTH,64+40*PROPORTION_WIDTH, kScreenWidth-40, 30)];
    [self.view addSubview:label_text];
    label_text.text = @"请使用常用邮箱,方便接收信息及密码找回";
    label_text.font = [UIFont systemFontOfSize:Font_SIZE_22];
    label_text.textColor = COLOT_TEXTGRAY;
    
    self.textField_email = [[UITextField alloc] initWithFrame:CGRectMake(20,label_text.bottom+22*PROPORTION_WIDTH,kScreenWidth - 40, 68*PROPORTION_WIDTH)];
    [self.view addSubview:self.textField_email];
    self.textField_email.placeholder = @"  请输入邮箱";
    self.textField_email.font = [UIFont systemFontOfSize:Font_SIZE_24];
    
    self.textField_email.layer.borderColor = RXDColor(228, 228, 228).CGColor;
    self.textField_email.layer.borderWidth = 1.0;
    self.textField_email.layer.cornerRadius = 5.0;
    self.textField_email.clipsToBounds = YES;
    
    //设置修改button
    self.button_getCheckCode = [[UIButton alloc] initWithFrame:CGRectMake(20, self.textField_email.bottom+56*PROPORTION_WIDTH,kScreenWidth - 40, 93*PROPORTION_WIDTH)];
    [self.view addSubview:self.button_getCheckCode];
    self.button_getCheckCode.backgroundColor = RXDColor(255, 118, 112);
    
    [self.button_getCheckCode setTitle:@"确 定" forState:UIControlStateNormal];
    
    [self.button_getCheckCode.titleLabel setFont:[UIFont systemFontOfSize:Font_SIZE_18*2]];
    [self.button_getCheckCode addTarget:self action:@selector(getCheckCodeButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.button_getCheckCode.layer.cornerRadius = 3.0;
    self.button_getCheckCode.clipsToBounds = YES;
    
}

#pragma mark ---- 获取验证码
- (void) getCheckCodeButton
{
    if (self.textField_email.text.length==0) {
        [UIView showAlertMsg:@"请填写完整信息"];
        return;
    }
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
//    self.textField_email.text = @"1498893132@qq.com";
    NSDictionary *dic_email = @{@"memberid":[[NSUserDefaults standardUserDefaults] objectForKey:@"memberid"],@"email":self.str_capcha,@"captcha":self.textField_email.text};
    
    NSString *strUrl;

    strUrl = [NSString stringWithFormat:@"%@member/bindemail",MRAPI];
    
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:strUrl parameters:dic_email success:^(id obj) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        NSString *str_false = obj[@"error"];
        
        NSLog(@"------%@－－－－%@",obj,obj[@"error"]);
        
        if (str_false.length==0)
        {
           [BaseViewController showMessage:@"已发往您的邮箱，请注意查看"];

            for (UIViewController *temp in self.navigationController.viewControllers) {
                
                if ([temp isKindOfClass:[MoreMessageVC class]]) {
                    [self.navigationController popToViewController:temp animated:YES];
                }
            }
        }
        else
        {
            [BaseViewController showMessage:str_false];
        }
        
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
        [UIView showAlertMsg:@"网络请求超时"];
    }];
}

- (void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
